<template>
  <div class="fml-relative">
    <div class="fml-layout">
      <div class="fml-body animated fadeInDown">
        <!-- 查询条件 -->
        <div class="fml-ui-forms">
          <fml-search :formConfig="formConfig" ref="searchComp"></fml-search>
        </div>
        <!-- 列表 -->
        <div class="fml-table-box">
          <fml-grid :PageConfig="pageConfig"> </fml-grid>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { defaultConfig, tableConfig } from "./config";
import { fmlRequest } from "@/utils";
export default {
  name: "fmlLogManagement",
  data() {
    return {
      //表单配置
      formConfig: {
        defaultConfig,
        tr:1,//树形所处行
        td:0,//树形所处列
        fmlForm: {
          startOperateTime:'',
          endOperateTime:'',
          organIds:[]
        }
      },
      // 列表
      pageConfig: {
        formHeight:280,//除表格外的高度
        showNum:true,//显示序列号
        tableConfig, //列表信息
        Api:'logList', //列表接口
        DataHandler(data){
          return data.map(item=>{
            if(item.operateType==0){
              item.operateType='登录'
            }else if(item.operateType==1){
              item.operateType='查询'
            }else if(item.operateType==2){
              item.operateType='新增'
            }else if(item.operateType==3){
              item.operateType='修改'
            }else if(item.operateType==4){
              item.operateType='删除'
            }
            return item
          })
        }
      }
    };
  },
  watch:{
    'formConfig.fmlForm.startOperateTime'(){
      this.watchDate("startOperateTime", "endOperateTime", 0, 1, 0, 2, 1);
    },
    'formConfig.fmlForm.endOperateTime'(){
     this.watchDate("startOperateTime", "endOperateTime", 0, 1, 0, 2, 2);
    },
  },
  methods: {
     // 获取机构
    getOrganizate(){
      fmlRequest.getOrganizate(this,0,'').then(result => {
        this.formConfig.defaultConfig.tr[1].td[0].options = result;
      });
    },
    lazyLoad(node,resolve){
      setTimeout(()=>{
        fmlRequest.getOrganizate(this,node.data.id,'').then(result => {
          resolve(result)
        });
      })
    },
    watchDate(startDate,endDate, firstStart,firstEnd,lastStart,lastEnd, stateHandle) {
      let start = this.formConfig.fmlForm[startDate];
      let end = this.formConfig.fmlForm[endDate];
      let endPicker = this.formConfig.defaultConfig.tr[lastStart].td[
        lastEnd
      ];
      let startPicker = this.formConfig.defaultConfig.tr[firstStart].td[
        firstEnd
      ];
      if (stateHandle == 2) {
        startPicker.pickerOptions = {
          disabledDate(time) {
            if(end){
              return (time.getTime() >= new Date(end) - 8.64e6);
            }else{
              return false
            }
          }
        };
      } else if (stateHandle == 1) {
        endPicker.pickerOptions = {
          disabledDate(time) {
            return time.getTime() <= new Date(start) - 8.64e7;
          }
        };
      }
    },
  },
  mounted() {
    this.formConfig.defaultConfig.tr[1].td[0].props.lazyLoad = this.lazyLoad;
    this.getOrganizate()
    this.$store.commit("setUpdateTable");
  }
};
</script>
